<?php

/**
 * Control_Footer 控件封装了页脚区域
 */
class Control_Footer extends QUI_Control_Abstract
{
    function render()
    {
        /**
         * 查询页脚区域所需的数据
         */
        $c = 'is_approbated = ? AND [owner.username] = ? AND is_picked';
        $this->_view['os_projects'] = Project::find($c, true, 'dualface')
            ->order('is_homepage_hot DESC, is_homepage DESC, rating DESC, created DESC')
            ->getAll();

        $c = 'is_approbated = ? AND is_picked = ? AND [owner.username] <> ?';
        $this->_view['picked_projects'] = Project::find($c, true, true, 'dualface')
            ->order('rating DESC, created DESC')
            ->top(5)
            ->getAll();

        $n = Q::ini('appini/site/footer_recents_num');
        $t = Topic::find()->order('order_pos DESC')->top($n)->asColl(false)->getAll();
        $a = Activity::find()->order('order_pos DESC')->top($n)->asColl(false)->getAll();
        $t = array_merge($t, $a);
        $this->_view['recents'] = Helper_Array::sortByCol($t, 'order_pos', SORT_DESC);
        unset($t);

        $this->_view['partner_links'] = Link::find('type = 1')->order('order_pos DESC, RAND()')->getAll();
        $this->_view['links'] = Link::find('type = 0')->order('order_pos DESC, RAND()')->limit(0)->getAll();

        /**
         * 通过控件视图渲染结果
         *
         * 对应的控件视图文件是 view/_controls/footer_control.php 。
         */
        return $this->_fetchView(dirname(__FILE__) . '/footer_view.php');
    }
}

